/*************************************************************************
	> File Name: Proxy.cc
	> Author: Joker
	> Mail: mahongtao@foxmail.com 
	> Created Time: 2020-09-22 11:51:19
 ************************************************************************/

#include "Proxy.h"

#include <iostream>
 
using std::cout;
using std::endl;

/*****************************
 *RealSubject
 *
 * **************************/
RealSubject::RealSubject(){
    cout << ">> RealSubject()" << endl;
}

RealSubject::~RealSubject(){
    cout << ">> ~RealSubject()" << endl;
}

void RealSubject::Request(){
    cout << "Request by RealSubject" << endl;
}

/*****************************
 *Proxy
 *
 * **************************/
Proxy::Proxy()
    :_pRealSubject(nullptr)
{
    cout << ">> Proxy()" << endl;
}

Proxy::~Proxy(){
    cout << ">> ~Proxy()" << endl;

    delete _pRealSubject;
    _pRealSubject = nullptr;
}

void Proxy::Request(){
    if(nullptr == _pRealSubject){
        cout << "Request by Proxy" << endl;
        _pRealSubject = new RealSubject();
    }

    _pRealSubject->Request();
}
